with ada.text_io;
use ada.text_io;
package body generic_stack is

    procedure initialize (object : in out stack ) is
    begin
	object.stack_list := new_list;
	object.top_link := object.stack_list.head;
	object.length := 0;
    end initialize;

    procedure adjust (object : in out stack) is
    begin
	null;
    end adjust;

    procedure finalize (object : in out stack) is
    begin
	null;
    end finalize;
    
    function len ( in_stack : stack_a) return stackRange is
    begin
	return in_stack.length;
    end len;

    function isempty ( in_stack : stack_a ) return boolean is
    begin
	return (boolean'(in_stack.length = 0));
    end isempty;

    procedure push ( in_stack : in out stack_a; element : in element_t) is
    begin
	if in_stack.length = max then
	    raise stack_overflow;
	end if;
	if in_stack.length = 0 then
	    in_stack.top_link := insert_first(in_stack.stack_list, element);
	else
	    in_stack.top_link := insert_after(in_stack.top_link, element);
	end if;
	in_stack.length := in_stack.length + 1;
    end push;

    procedure pop ( in_stack : in out stack_a; element : out element_t) is
    begin
	if in_stack.length = 0 then
	    raise stack_underflow;
	end if;
	element := in_stack.top_link.data;
	in_stack.top_link := delete_last ( in_stack.stack_list );
	in_stack.length := in_stack.length - 1;
    end pop;

    procedure top ( in_stack : in stack_a; element : out element_t) is
    begin
	if in_stack.length = 0 then
	    raise stack_underflow;
	end if;
	element := in_stack.top_link.data;
    end top;

end generic_stack;
